/*
* ============================================================================
*  Name     : CLogExEngine from LogExEngine.h
*  Part of  : LogExample
*  Created  : 26.05.2005 by Forum Nokia 
*  Description:
*     provides interface to Log engine
*  Version  : 1.0
*  Copyright: Nokia Corporation 
* ============================================================================
*/

#ifndef __LOGEXENGINE_H__
#define __LOGEXENGINE_H__

// INCLUDE FILES
#include <e32base.h>
#include <f32file.h>        // RFs
#include <logcli.h>			// CLogClient
#include <logview.h>		// CLogViewEvent

#include "EventsObserver.h"

enum
	{
	EGetEvent,
	EGetRecent,
	EAddEvent,
	EAddEventType,
	EDeleteEvent,
	ENoEvent,
	ESleep
	};


//CLASS DECLARATION
class CLogExEngine : public CActive
	{

public:
		void StopReadEvent();

	/**
	* Symbian OS default constructor
	*/
	CLogExEngine();	
	
	/**
	* Two-phased constructor.
	*/
	static CLogExEngine* NewL();
	
	/**
	* Two-phased constructor.
	*/
	static CLogExEngine* NewLC();
	
	/**
	* Destructor
	*/
	virtual ~CLogExEngine();
	
	/**
	* Reads events from the main event database
	*/
	void ReadEventsL();
	
	/**
	* Reads events from the main event database
	*/	
	void ReadRecentEventsL();
	
	/**
	* Adds random event to the log engine database
	*/
	void AddRandomEventL(); 
	
	/**
	* Adds event to the main event database
	*/	
	void AddEventTypeToLogEngineL();
	
	/**
	* Adds own event to the log engine database
	*/
	void AddOwnEventL();
		
	/** 
	* Deletes the event in param from the log engine database
	* @param aLogId event Id
	*/
	void DeleteEventL(TLogId& aLogId);

	/**
	* Sets observer given in param as events observer
	* @param aObserver observer
	*/
	void SetObserver(MEventsObserver* aObserver);
	
	/**
	* Removes current events observer
	*/
	void RemoveObserver();
	
	/**
	* Sets recent events observer
	* @param aObserver observer
	*/
	void SetRecentObserver(MEventsObserver* aObserver);
	
	/**
	* Removes current recents events observer
	*/	
	void RemoveRecentObserver();

	/** 
	* Convenience methods for filtering events, only
	* one filter at time can be active. When none set
	* no filtering, all will be shown
	*/
	/**
	* Sets incoming events filtering
	*/
	void SetEventFilterDirectionIncoming();
	
	/**
	* Sets outgoing events filtering
	*/
	void SetEventFilterDirectionOutgoing();
	
	/**
	* Sets voice type events filtering
	*/
	void SetEventFilterEventTypeVoice();
	
	/**
	* Sets sms events filtering
	*/
	void SetEventFilterEventTypeSMS();
	
	/**
	* Clears filters
	*/
	void ClearEventFilter();

private:

	/**
	* Symbian 2-phase constructor
	*/
	void ConstructL();
	
	/**
	* From CActive
	*/
	void RunL(); 
	
	/**
	* From CAktive
	*/
	TInt RunError(TInt anError);
	
	/**
	* From CActive
	*/
	void DoCancel(); 

	/**
	* CreateRandomLogEvent()
	*
	* Creates random log events which can be set to log engine
	* Needed for emulator test 
	*/
	CLogEvent* CreateRandomLogEventL();

	/**
	* Adds new event type to the log engine
	*/
	CLogEventType* OwnLogEventTypeL();
	
	/**
	* Creates random number
	* @param aLimiter number to generate random int
	* @return random number
	*/
	TInt Random(const TInt& aLimiter);
	
private: // Data Members

	RFs iFs;
	
	CLogClient* iLogClient;
	CLogViewEvent* iLogViewEvent;
	CLogViewRecent* iLogViewRecent;
	
	// Filters for event log
	CLogFilter* iLogFilter;
	
	// This is always empty
	// It is used to clear the active filter - iLogFilter
	CLogFilter* iEmptyLogFilter;
	
	CLogEvent* iLogEvent;
	CLogEventType* iLogEventType;
		
	MEventsObserver* iObserver;
	MEventsObserver* iRecentObserver;
	
	TInt iDeletedIndex;

	TBool iOwnEvenTypeRegistered;
	
	TInt iTask; // task for RunL
	};

#endif	

// End of file
